package com.yanq.liancar.activity;
/*
 *  @创建者     Administrator
 *  @创建时间   2018/12/17  14:11
 *  @描述       ${TODO}
 */

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.gyf.barlibrary.ImmersionBar;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.base.BaseToolbarActivity;
import com.yanq.liancar.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IntegralDetailsActivity extends BaseToolbarActivity {
    @BindView(R.id.webView)
    WebView webView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_integraldetails);
        ButterKnife.bind(this);
        ImmersionBar.with(this).statusBarDarkFont(true).statusBarColor(R.color.white).init();
        mTvTitle.setText("积分商品详情");

        setWebData(getIntent().getStringExtra("url"));

    }

    @SuppressLint("SetJavaScriptEnabled")
    private void setWebData(String url) {
        ToastUtil.showProgressDialog(this);
        WebSettings setting = webView.getSettings();
        setting.setJavaScriptEnabled(true);
        setting.setBlockNetworkImage(false);
        setting.setSupportZoom(true);
        setting.setUseWideViewPort(true);
        setting.setAllowFileAccess(true);
        setting.setCacheMode(WebSettings.LOAD_NO_CACHE);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            setting.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                ToastUtil.dismissProgressDialog();
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                ToastUtil.dismissProgressDialog();
            }
        });
    }
}
